//
//  CJExten+StrOC.swift
//  CJCore
//
//  Created by 陈警卫 on 2024-06-18.
//

import UIKit
import Foundation

public extension NSString {
    
    var string: String {
        return self as String
    }
}

public extension NSString {
    
    /// 去除前后空格
    @objc var cj_trimSpace: NSString {
        let value = string.cj_trimSpace as NSString
        return value
    }
    
    /// 去除前后换行
    @objc var cj_trimLine: NSString {
        let value = string.cj_trimLine as NSString
        return value
    }
    
    /// 去除前后空格和换行
    @objc var cj_trimSpaceAndLines: NSString {
        let value = string.cj_trimSpaceAndLines as NSString
        return value
    }
    
    /// 去除所有空格
    @objc var cj_trimAllSpace: NSString {
        let value = string.cj_trimAllSpace as NSString
        return value
    }
    
    /// 去除所有换行
    @objc var cj_trimAllLines: NSString {
        let value = string.cj_trimAllLines as NSString
        return value
    }
    
    /// 去除所有空格和换行
    @objc var cj_trimAllSpaceAndLines: NSString {
        let value = string.cj_trimAllSpaceAndLines as NSString
        return value
    }
    
    /// 使用正则表达式替换
    @objc func cj_replace(regex: String, with: String, options: NSRegularExpression.Options = []) -> NSString {
        let value = string.cj_replace(regex: regex, with: with, options: options) as NSString
        return value
    }
}

public extension NSString {
    
    /// 判断包含中文符号
    @objc var cj_includeChineseSymbol: Bool {
        let value = string.cj_includeChineseSymbol
        return value
    }
    
    /// 验证包含中文
    @objc var cj_includeChinese: Bool {
        let value = string.cj_includeChinese
        return value
    }
    
}

public extension NSString {
    /// 验证数字
    @objc var cj_isDecimal: Bool {
        let value = string.cj_isDecimal
        return value
    }
    
    /// 验证数字
    @objc var cj_isNumber: Bool {
        let value = string.cj_isNumber
        return value
    }
    
    /// 验证数字和小数点
    @objc var cj_isNumberAndPoint: Bool {
        let value = string.cj_isNumberAndPoint
        return value
    }
    
    /// 验证邮箱
    @objc var cj_isEmail: Bool {
        let value = string.cj_isEmail
        return value
    }
    
    /// 验证手机号码
    @objc var cj_isPhone: Bool {
        let value = string.cj_isPhone
        return value
    }
    
    /// 验证邮政编码
    @objc var cj_isPostal: Bool {
        let value = string.cj_isPostal
        return value
    }
    
    /// 验证全中文
    @objc var cj_isAllChinese: Bool {
        let value = string.cj_isAllChinese
        return value
    }
    
    /// 简单验证身份证
    @objc var cj_isIDCard: Bool {
        let value = string.cj_isIDCard
        return value
    }
    
    /// 密码验证 既有数字又有字母
    @objc var cj_isPassword: Bool {
        let value = string.cj_isPassword
        return value
    }
    
    /// 密码验证 既有数字又有字母 位数
    @objc func cj_isPassword(min: Int, max: Int) -> Bool {
        let value = string.cj_isPassword(min: min, max: max)
        return value
    }
    
    /// 验证url字符串
    @objc var cj_isUrlString: Bool {
        let value = string.cj_isUrlString
        return value
    }
}

public extension NSString {
    
    /// MD5
    @available(iOS, introduced: 2.0, deprecated: 13.0, message: "This function is cryptographically broken and should not be used in security contexts. Clients should migrate to SHA256 (or stronger).")
    @objc var cj_md5: NSString? {
        let value = string.cj_md5 as? NSString
        return value
    }
    
    /// base64编码
    @objc var cj_base64Encode: NSString {
        let value = string.cj_base64Encode as NSString
        return value
    }
    
    /// base64解码
    @objc var cj_base64Decode: NSString {
        let value = string.cj_base64Decode as NSString
        return value
    }
    
    /// URL编码
    @objc var cj_urlEncode: NSString {
        let value = string.cj_urlEncode as NSString
        return value
    }
    
    /// URL编码
    @objc var cj_urlEncodeURL: URL? {
        let value = string.cj_urlEncodeURL
        return value
    }
    
    /// URL解码
    @objc func cj_urlDecode() -> NSString {
        let value = string.cj_urlDecode() as NSString
        return value
    }
}

public extension NSString {
    
    /// 转Class
    @objc func cj_class() -> AnyClass? {
        let Class: AnyClass? = NSClassFromString(string)
        return Class
    }
    
    /// 判断是否包含 ignoringCase 忽略大小写
    @objc func cj_contains(sub: String, ignoringCase: Bool = false) -> Bool {
        let value = string.cj_contains(sub: sub, ignoringCase: ignoringCase)
        return value
    }
    
    /// 根据字符进行分隔
    @objc func cj_separatedBy(char: CharacterSet) -> [NSString] {
        let value = string.cj_separatedBy(char: char) as [NSString]
        return value
    }
    
}

public extension NSString {
    
    /// 取字符串
    @objc func cj_sub(start: Int, end: Int) -> NSString {
        let value = string.cj_sub(start: start, end: end) as NSString
        return value
    }
    
    /// 取字符串
    @objc func cj_sub(loc: Int, len: Int) -> NSString {
        let value = string.cj_sub(loc: loc, len: len) as NSString
        return value
    }
    
    /// 取字符串
    @objc func cj_sub(to index: Int) -> NSString {
        let value = string.cj_sub(to: index) as NSString
        return value
    }
    
    /// 取字符串
    @objc func cj_sub(from index: Int) -> NSString {
        let value = string.cj_sub(from: index) as NSString
        return value
    }
    
    /// 取字符串
    @objc func cj_index(loc: Int) -> NSString {
        let value = string.cj_index(loc: loc) as NSString
        return value
    }
    
}

public extension NSString {
    
    /// 转Int
    @objc var cj_int: Int {
        let value = string.cj_int
        return value
    }
    
    /// 转Int
    /// 4舍5入
    @objc var cj_intRound: Int {
        let value = string.cj_intRound
        return value
    }

    /// 转Int
    /// 下取整
    @objc var cj_intFloor: Int {
        let value = string.cj_intFloor
        return value
    }
    
    
    /// 转Int
    /// 上取整
    @objc var cj_intCeil: Int {
        let value = string.cj_intCeil
        return value
    }
    
    
    /// 转Data
    /// encoding 默认.utf8
    @objc func cj_data() -> Data? {
        let value = string.cj_data(encoding: .utf8)
        return value
    }
    
    /// 转拼音
    @objc func cj_pinyin(_ ton: Bool = false) -> String {
        let value = string.cj_pinyin(ton)
        return value
    }
    
    /// 解析JSON
    @objc var cj_dict: Any? {
        let value = string.cj_dict
        return value
    }
    
    /// ascii字符串
    @objc func cj_asciiString() -> NSString {
        let value = string.cj_asciiString() as NSString
        return value
    }
    
    /// 复制
    @objc func cj_copy() {
        string.cj_copy()
    }
}

public extension NSString {
    
    /// 时间format字符串转Date
    @objc func cj_date(format: String = "YYYY-MM-dd HH:mm:ss", timeZone: TimeZone?, locale: Locale?) -> Date {
        let value = string.cj_date(format: format, timeZone: timeZone, locale: locale)
        return value
    }
    
    /// 时间戳转Date
    @objc var cj_stampToDate: Date {
        let value = string.cj_stampToDate
        return value
    }
    
    /// 时间戳转DateFormat字符串
    /// format默认 "YYYY-MM-dd HH:mm:ss"
    @objc func cj_dateString(format: String = "YYYY-MM-dd HH:mm:ss") -> NSString {
        let value = string.cj_dateString(format: format) as NSString
        return value
    }
    
    /// 时间戳转时钟 00:00:00
    @objc var cj_clock: NSString {
        let value = string.cj_clock as NSString
        return value
    }
    
    /// 时间戳转时钟 00:00/00:00:00
    @objc var cj_clockFits: NSString {
        let value = string.cj_clockFits as NSString
        return value
    }
}

public extension NSString {
    
    /// 16进制字符串转Data
    @objc var cj_hexData: Data {
        let value = string.cj_hexData
        return value
    }
    
    /// 16进制字符串转10进制字符串
    @objc var cj_hexToDecimal: NSString {
        let value = string.cj_hexToDecimal as NSString
        return value
    }
    
    /// 16进制字符串转2进制字符串
    @objc var cj_hexToBinary: NSString {
        let value = string.cj_hexToBinary as NSString
        return value
    }
    
    /// 10进制字符串转16进制字符串
    @objc var cj_decimalToHex: NSString {
        let value = string.cj_decimalToHex as NSString
        return value
    }
    
    /// 10进制字符串转2进制字符串
    @objc var cj_decimalToBinary: NSString {
        let value = string.cj_decimalToBinary as NSString
        return value
    }
    
    /// 2进制字符串转16进制字符串
    @objc var cj_binaryToHex: NSString {
        let value = string.cj_binaryToHex as NSString
        return value
    }
    
    /// 2进制字符串转10进制字符串
    @objc var cj_binaryToDecimal: NSString {
        let value = string.cj_binaryToDecimal as NSString
        return value
    }
}

public extension NSString {
    
    /// 获取字符串Size
    @objc func cj_size(font: UIFont, expectSize: CGSize, lineBreakMode: NSLineBreakMode = .byWordWrapping) -> CGSize {
        let value = string.cj_size(font: font, expectSize: expectSize, lineBreakMode: lineBreakMode)
        return value
    }
    
    /// 获取字符串height
    @objc func cj_height(font: UIFont, width: CGFloat) -> CGFloat {
        let value = string.cj_height(font: font, width: width)
        return value
    }
    
    /// 获取字符串width
    @objc func cj_width(font: UIFont, height: CGFloat) -> CGFloat {
        let value = string.cj_width(font: font, height: height)
        return value
    }
    
    /// 获取字符串height
    @objc func cj_lableHeight(font: UIFont, width: CGFloat) -> CGFloat {
        let value = string.cj_lableHeight(font: font, width: width)
        return value
    }
    
    /// 获取字符串width
    @objc func cj_lableWidth(font: UIFont, height: CGFloat) -> CGFloat {
        let value = string.cj_lableWidth(font: font, height: height)
        return value
    }
    
}

